package ControlLayer;
import ModelLayer.*;

/**
 * the RentCtr class is the controller class for rent objects and rentContainer and it's purpose
 * is to connect rent objects and rentContainer to the TUI layer
 */

public class RentCtr
{
    private Rent rent;
    private RentContainer rentContainer;
    private AddressBook addressBook;
    private DVD dvd;
    private DVDContainer dvdContainer;
    private Person person;

    public RentCtr()
    {
        rentContainer = rentContainer.getInstance(); 
        addressBook = AddressBook.getInstance();
        dvdContainer = DVDContainer.getDVDContainer();
    }

    /**
     * createRentWithId creates an rent object with a person object and copy object by
     * using the ID of a person
     */
    
    public void createRentWithId(int searchId, int dvdId, String searchSerialNumber, int id, String date, int period)
    {
        Person person = addressBook.findPersonId(searchId);
       // DVD dvd2 = dvdContainer.searchDVD(dvdId);
        Copy copyRented = dvdContainer.searchDVD(dvdId).searchCopy(searchSerialNumber);
        Rent newRent = new Rent(id, date, period, copyRented, person);
        rentContainer.addRent(newRent);
    }

    /**
     * createRentWithId creates an rent object with a person object and copy object by
     * using the name of a person
     */
    
    public void createRentWithName(String searchName, int dvdId, String searchSerialNumber, int id, String date, int period)
    {
        Person person = addressBook.findPersonName(searchName);
        Copy copyRented = dvdContainer.searchDVD(dvdId).searchCopy(searchSerialNumber);
        Rent newRent = new Rent(id, date, period, copyRented, person);
        rentContainer.addRent(newRent);
    }

    /**
     * returnDvd changes a rent object's status to Returned
     */
    
    public void returnRent(String serialNumber)
    {
        Rent rent2 = rentContainer.findRent(serialNumber);
        rent2.setStatus("Returned");

    }
    
    /**
     * showLoanInfo prints the info connected to a rent object
     */
    
    public void showLoanInfo(int rentId)
    {
        rentContainer.showRentInfo(rentId); 
    }

}
